package com.ruoyi.system.service.impl;

import com.ruoyi.system.domain.ArchiveReceiveStat;
import com.ruoyi.system.mapper.ArchiveReceiveStatMapper;
import com.ruoyi.system.service.ArchiveReceiveStatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 档案接收统计 Service 实现类
 *
 * @author 你的名字
 */
@Service
public class ArchiveReceiveStatServiceImpl implements ArchiveReceiveStatService {
    @Autowired
    private ArchiveReceiveStatMapper archiveReceiveStatMapper;

    @Override
    public List<ArchiveReceiveStat> selectArchiveReceiveStatList(ArchiveReceiveStat archiveReceiveStat) {
        return archiveReceiveStatMapper.selectArchiveReceiveStatList(archiveReceiveStat);
    }

    @Override
    public ArchiveReceiveStat selectArchiveReceiveStatById(Long id) {
        return archiveReceiveStatMapper.selectArchiveReceiveStatById(id);
    }

    @Override
    public int insertArchiveReceiveStat(ArchiveReceiveStat archiveReceiveStat) {
        return archiveReceiveStatMapper.insertArchiveReceiveStat(archiveReceiveStat);
    }

    @Override
    public int updateArchiveReceiveStat(ArchiveReceiveStat archiveReceiveStat) {
        return archiveReceiveStatMapper.updateArchiveReceiveStat(archiveReceiveStat);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int batchSaveArchiveReceiveStat(List<ArchiveReceiveStat> list) {
        if (list.isEmpty()) {
            return 0; // 空列表直接返回
        }
        // 2. 删除指定年份的旧数据
        archiveReceiveStatMapper.deleteAll();
        // 3. 批量插入新数据
        return archiveReceiveStatMapper.batchInsertArchiveReceiveStat(list);
    }
}